<template>
	<view>
		<view class="padding-lr">
			<view class="padding-xl">
				<view class="text-bold text-lg margin-bottom-xl" style="letter-spacing: 4rpx;">忘记密码</view>
				<view class="ipt-group">
					<image src="../../static/images/a1.png" mode=""></image>
					<input type="text" class="ipt" v-model="form.mobile" placeholder="输入手机号" placeholder-class="ipt-pc" />
				</view>
				<view class="ipt-group">
					<image src="../../static/images/a2.png" mode=""></image>
					<input password class="ipt" v-model="form.password" placeholder="设置密码" placeholder-class="ipt-pc" />
				</view>
				<view class="ipt-group">
					<image src="../../static/images/a2.png" mode=""></image>
					<input password class="ipt" v-model="form.password_confirmation" placeholder="确认密码" placeholder-class="ipt-pc" />
				</view>
				<view class="ipt-group">
					<image src="../../static/images/a4.png" mode=""></image>
					<input type="text" class="ipt" v-model="form.code" placeholder="输入验证码" placeholder-class="ipt-pc" />
					<view class="text-orange yzm" @click="getCode">
						{{tips}}
					</view>
					<u-verification-code :seconds="60" ref="uCode" @change="codeChange"></u-verification-code>
				</view>
			</view>
		</view>
		
		<view class="btn-wrap">
			<button class="btn" @click="forget">
				确定
			</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					mobile: '',
					password: '',
					password_confirmation: '',
					code: ''
				},
				tips: '获取验证码',
			};
		},
		methods: {
			codeChange(e) {
				this.tips = e
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					uni.showLoading({
						title: '正在获取验证码'
					})
					this.$u.post('/passport/getCode', {
						mobile: this.form.mobile,
						type: 'forget'
					}).then(res => {
						uni.hideLoading();
						if (res.data.code==0) {
							this.$msg(res.data.msg)
							this.$refs.uCode.start();
						} else {
							this.$msg(res.data.msg)
						}
					})
				} else {
					this.$u.toast('请稍后再试');
				}
			},
			forget() {
				this.$u.post('/passport/forget', this.form).then(res => {
					if (res.data.code==0) {
						this.$msg(res.data.msg, 1000, true).then(res => this.$goto(1))
					} else {
						this.$msg(res.data.msg)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.ipt-group {
		background:rgba(245,245,245,1);
		border-radius:14rpx;
		width: 100%;
		height: 90rpx;
		margin-top: 36rpx;
		display: flex;
		align-items: center;
		padding: 0 20rpx;
		position: relative;
		
		image {
			width: 50rpx;
			height: 50rpx;
			margin-right: 20rpx;
		}
		.ipt {
			color: gray;
		}
		.ipt-pc {
			color: #D3D3D3;
		}
		.yzm {
			position: absolute;
			right: 30rpx;
		}
	}
	.btn-wrap {
		position: absolute;
		bottom: 160rpx;
		width: 100%;
		display: flex;
		justify-content: center;
		.btn {
			width:561rpx;
			height:88rpx;
			line-height: 88rpx;
			text-align: center;
			color: white;
			background:linear-gradient(90deg, #dcbe85 0%,#c69542 100% );
			border-radius:44rpx;
			
		}
	}
</style>
